package com.javaAPI.demo2;

public class Student extends Parent {
    //Student extends Object  直接继承
    //public class Student   间接继承

    private int age;
    private String name;

    public Student() {
        super();
    }

    public Student(String name, int age) {
        this.age = age;
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "age=" + age + ", name='" + name;

    }

    /*
     * 重写父类中的equals方法
     * */
    @Override
    public boolean equals(Object obj) {
        //内存地址相同
        if (this == obj) {
            return true;
        } else if (obj == null || this.getClass() != obj.getClass()) {
            //比较两个对象的类型是否一致,  this.getClass() != obj.getClass()
            return false;//为空或两个对象类型不一致，返回false
        }
        Student student = (Student) obj;
        //两个对象类型一致
        /*
         * 多态强制转换 (Student) obj
         * String中 equals判断两个字符串值是否相等------String底层重写了object父类
         * */
        return this.age == student.age && this.name.equals(((Student) obj).name);
    }
}
